/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package businessDelegates;

import businessObjects.Esquema;
import businessObjects.Estado;
import businessObjects.Pauta;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import sessionFacades.PautaFacadeRemote;

/**
 *
 * @author williamprado
 */
@EJB(name="pautafr", beanInterface = PautaFacadeRemote.class)
public class PautaBusinessDelegate {

    
    //private PautaFacadeRemote pautaFacadeBean;

    public PautaBusinessDelegate(){

    }

    public void guardarPauta(Pauta p){
       try {
            Context ctx = new InitialContext();
            PautaFacadeRemote pautaFacadeBean = (PautaFacadeRemote) ctx.lookup("java:comp/env/pautafr");
              pautaFacadeBean.guardarPauta(p);
        } catch (NamingException ex) {
            Logger.getLogger(PautaBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void actualizarPauta(Pauta p){
        try {
            Context ctx = new InitialContext();
            PautaFacadeRemote pautaFacadeBean = (PautaFacadeRemote) ctx.lookup("java:comp/env/pautafr");
            pautaFacadeBean.actualizarPauta(p);
        } catch (NamingException ex) {
            Logger.getLogger(PautaBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void eliminarPauta(int id){
        try {
            Context ctx = new InitialContext();
            PautaFacadeRemote pautaFacadeBean = (PautaFacadeRemote) ctx.lookup("java:comp/env/pautafr");
            pautaFacadeBean.eliminarPauta(id);
        } catch (NamingException ex) {
            Logger.getLogger(PautaBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Pauta consultarPauta(int id){

          try {
            Pauta p = new Pauta();
            Context ctx = new InitialContext();
            PautaFacadeRemote pautaFacadeBean = (PautaFacadeRemote) ctx.lookup("java:comp/env/pautafr");
            p = pautaFacadeBean.consultarPauta(id);
            return p;
        } catch (NamingException ex) {
            Logger.getLogger(ClienteBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }        
    }

    public Esquema findEsquema(int id){
        try {
            Context ctx = new InitialContext();
            PautaFacadeRemote pautaFacadeBean = (PautaFacadeRemote) ctx.lookup("java:comp/env/pautafr");
            return pautaFacadeBean.findEsquema(id);
        } catch (NamingException ex) {
            Logger.getLogger(PautaBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }        
    }

    public Estado findEstado(int id){
        try {
            Context ctx = new InitialContext();
            PautaFacadeRemote pautaFacadeBean = (PautaFacadeRemote) ctx.lookup("java:comp/env/pautafr");
            return pautaFacadeBean.findEstado(id);
        } catch (NamingException ex) {
            Logger.getLogger(PautaBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }        
    }

    public List<Pauta> consultarPautasBasicas(){
        try {
            Context ctx = new InitialContext();
            PautaFacadeRemote pautaFacadeBean = (PautaFacadeRemote) ctx.lookup("java:comp/env/pautafr");
            List<Pauta> p = pautaFacadeBean.consultarPautasBasicas();
            return p;
        } catch (NamingException ex) {
            Logger.getLogger(PautaBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }        
    }

    public List<Pauta> consultarPautasPremium(){
        try {
            Context ctx = new InitialContext();
            PautaFacadeRemote pautaFacadeBean = (PautaFacadeRemote) ctx.lookup("java:comp/env/pautafr");
            List<Pauta> p = pautaFacadeBean.consultarPautasPremium();
            return p;
        } catch (NamingException ex) {
            Logger.getLogger(PautaBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }        
    }

    public List<Pauta> consultarPautasCliente(String login){
        try {
            Context ctx = new InitialContext();
            PautaFacadeRemote pautaFacadeBean = (PautaFacadeRemote) ctx.lookup("java:comp/env/pautafr");
            List<Pauta> p = pautaFacadeBean.consultarPautasCliente(login);
            return p;
        } catch (NamingException ex) {
            Logger.getLogger(PautaBusinessDelegate.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }        
    }
}